function getLayerByTitle({ map, title }) {
  /* 1、获取所有的图层 */
  let layers = map.getLayers().getArray();
  /* 2、获取==title的图层  find*/
  let target = layers.find((item) => {
    if (item.get('title')) {
      return item.get('title') == title;
    }
  });
  /* 3、返回图层 */
  return target;
}
function setPntStyle({ radius = 8, color = '#333' }) {
  return new ol.style.Style({
    //形状
    image: new ol.style.Circle({
      radius,
      fill: new ol.style.Fill({
        color,
      }),
    }),
  });
}
export function setLineStyle({ width = 4, color = 'green' }) {
  return new ol.style.Style({
    stroke: new ol.style.Stroke({
      color,
      width,
    }),
  });
}
function setAreaStyle({ fill = 'green', stroke = '#ffcc33', width = 2 }) {
  return new ol.style.Style({
    //填充色
    fill: new ol.style.Fill({
      color: fill,
    }),
    //边线颜色
    stroke: new ol.style.Stroke({
      color: stroke,
      width,
    }),
  });
}
/* 变量名和函数名都要小写 */

function JSONToFeature(data) {
  if (data.type == 'FeatureCollection') {
    return new ol.format.GeoJSON().readFeatures(data);
  } else if (data.type == 'Feature') {
    return new ol.format.GeoJSON().readFeature(data);
  }
}
function FeatureToJSON(feature) {
  let format = new ol.format.GeoJSON();
  if (feature instanceof Array) {
    return format.writeFeaturesObject(feature);
  } else {
    return format.writeFeatureObject(feature);
  }
}
